package com.lin.filegraph.utils.compdg;

import com.lin.filegraph.utils.threshold.Threshold;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @description:
 * @author: linhuaixu
 * @time: 2023/5/18 10:27
 */

public class ComponentNode implements Comparable<ComponentNode> {
    private int ID=0;//唯一id
    private String projectPath;
    private String strComponentName;//节点名
    private boolean isFromPre;//记录是不是上个版本保留
    private List<String> listOfFiles;//包含的文件
    private List<String> listOfDirs;//包含的子目录   包含的子模块
    private int locOfCom =0;//有效代码行
    private boolean isRegion = false;//是否为域节点或者中心节点
    private boolean ischeck=false;
    private int level=-1;//聚类层数
    public boolean isFromStrongDep;//预处理强依赖聚合
    private int preNum=0;//上次最大数目
    public boolean isSplited = false;//代表节点已经分割或者节点已经被文档化
    private boolean isFeature=false;

    //by suxiaowei
    //该节点的中心节点
    public double cog_divide_size=0;
    private String centerName;
    public void setCenternode(String name)
    {
        this.centerName=name;
    }
    public String getCenternode(){
        return centerName;
    }

    public ComponentNode(String strComponentName, List<String> listOfFiles, int LOC, String projectPath) {
        this(strComponentName, listOfFiles, projectPath);
        this.locOfCom = LOC;
        this.lay_components=new HashSet<String>();
    }
    //与此组件属于同一层的组件
    private Set<String> lay_components;
    //分层模式下与该组件属于同一层的组件
    public Set<String> getLay_components() {
        return lay_components;
    }
    public void setLay_components(Set<String> lay_components) {
        this.lay_components = lay_components;
    }
    // end by suxiaowei
    public ComponentNode(String strComponentName, List<String> listOfFiles, String projectPath) {
        this.strComponentName = strComponentName;
        this.listOfFiles = listOfFiles;
        this.listOfDirs = new ArrayList<>();
        this.projectPath = projectPath;
        this.isFromPre=false;
        this.lay_components=new HashSet<String>();
    }

    public ComponentNode(String strComponentName, String projectPath) {
        this.lay_components=new HashSet<String>();
        this.strComponentName = strComponentName;
        this.listOfFiles = new ArrayList<>();
        this.listOfDirs = new ArrayList<>();
        this.projectPath = projectPath;
        this.isFromPre=false;
    }

    public ComponentNode(String strComponentName) {
        this(strComponentName, null);
    }

    public String getStrComponentName() {
        return strComponentName;
    }

    public void setStrComponentName(String str) {
//		if(!strComponentName.startsWith(Threshold.TEST+Threshold.SPACER))
//			if(isFeature&&strComponentName.equals(Threshold.TEST))
//				return;
        this.strComponentName = str;
    }

    public void reComName(String name) {
        this.setStrComponentName(name+ Threshold.SPACER+ ID);
    }

    public List<String> getAllFiles() {
        return listOfFiles;
    }

    public List<String> getAllDirs() {
        return listOfDirs;
    }

    public void addFile(String file) {
        if(!listOfFiles.contains(file))
            listOfFiles.add(file);
    }

    public void addDir(String dir) {
        listOfDirs.add(dir);
    }
    public void removeDir() {
        listOfDirs.clear();
    }

    public int getLocOfCom() {
        return locOfCom;
    }

    public void addLocOfCom(int numOfFiles) {
        this.locOfCom += numOfFiles;
    }

    @Override
    public String toString() {
        return "[ComponentNode]  " + strComponentName + " "+listOfFiles.size()+" "+listOfFiles;
    }

    public boolean isRegion() {
        return isRegion;
    }

    public void setRegion(boolean isRegion) {
        this.isRegion = isRegion;
    }

    public boolean isFromPre() {
        return isFromPre;
    }

    public void setFromPre(boolean isFromPre) {
        this.isFromPre = isFromPre;
    }

    public int getID() {
        return ID;
    }

    public void setID(int num) {
        this.ID = num;
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    @Override
    public int compareTo(ComponentNode o) {
        return this.getStrComponentName().compareTo(o.getStrComponentName());
    }

    public int getPreNum() {
        return preNum;
    }
    public void setPreNum(int preNum) {
        this.preNum = preNum;
    }
    public String getProjectPath() {
        return projectPath;
    }

    public boolean isIscheck() {
        return ischeck;
    }

    public void setIscheck(boolean ischeck) {
        this.ischeck = ischeck;
    }

    public int getLevel() {
        return level;
    }
    public void setLevel(int level) {
        this.level = level;
    }
    public boolean isFeature() {
        return isFeature;
    }
    public void setFeature(boolean isFeature) {
        this.isFeature = isFeature;
    }
    public boolean isFromStrongDep() {
        return isFromStrongDep;
    }
    public void setFromStrongDep(boolean isFromStrongDep) {
        this.isFromStrongDep = isFromStrongDep;
    }

}
